package cn.i7baozh.cloud.payment.handler;

import cn.i7baozh.cloud.api.dto.ReturnResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author zhangbaoqi532
 * @date 2024/12/25
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler({RuntimeException.class})

    //这个状态码决定了调用方即消费者处理方式，如果返回200那么消费者正常处理（业务异常）
    // 非200则是代码异常 用消费者多试几次就体现出来了
//    @ResponseStatus(HttpStatus.OK)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ReturnResponse<String> exception(Exception e) {
        log.error("error :{}", e.getMessage(), e);
        return ReturnResponse.fail("501", "出错了");
    }
}
